<p>当我们覆写<code>clone()</code>方法时，需要同时实现<code>Cloneable</code>接口。
  并且我们建议在<code>clone()</code>方法中要调用<code>super.clone()</code></p>

<h2>不规范的代码</h2>

<pre>
class BaseClass {  // 不符合规定； 要实现Cloneable接口
  @Override
  public Object clone() throws CloneNotSupportedException {   //不符合规定；应该返回super.clone()实例
    return new BaseClass();
  }
}

class DerivedClass extends BaseClass implements Cloneable {
  /* Does not override clone() */

  public void sayHello() {
    System.out.println("Hello, world!");
  }
}

class Application {
  public static void main(String[] args) throws Exception {
    DerivedClass instance = new DerivedClass();
    ((DerivedClass) instance.clone()).sayHello();              //因为违反了不变式＃2，所以引发了ClassCastException
  }
}
</pre>
<h2>正确解决方案</h2>

<pre>
class BaseClass implements Cloneable {
  @Override
  public Object clone() throws CloneNotSupportedException {    // 正确
    return super.clone();
  }
}

class DerivedClass extends BaseClass implements Cloneable {
  /* Does not override clone() */

  public void sayHello() {
    System.out.println("Hello, world!");
  }
}

class Application {
  public static void main(String[] args) throws Exception {
    DerivedClass instance = new DerivedClass();
    ((DerivedClass) instance.clone()).sayHello();              // 能打印 "Hello, world!"
  }
}
</pre>
<h2>更多</h2>

<ul>
<li> <a href="http://cwe.mitre.org/data/definitions/580.html">MITRE, CWE-580</a> - clone() Method Without super.clone()</li>
</ul>

